class Solution {
    public int removeElement(int[] nums, int val) {
        int length = nums.length;
        for (int i = nums.length - 1; i > 0; i--) {
            if (nums[i] == val) {
                nums[i] = nums[length - 1];
                length--;
            }
        }
        return length;
    }

    public int removeElement2(int[] nums, int val) {
        int quick = 0, slow = 0;
        for (; quick < nums.length; quick++) {
            if (nums[quick] != val) {
                nums[slow++] = nums[quick];
            }
        }
        return slow;
    }
}